package bmatch.tech.hello.resource;

import bmatch.tech.hello.auth.TokenNeeded;
import bmatch.tech.hello.dao.CommonCityCodeMapper;
import bmatch.tech.hello.model.CommonCityCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * CityResource的注释
 *
 * @author: Awake
 * @date: 2018-12-04 21:56
 **/
@Component
@Path("city")
public class CityResource {

    @Autowired
    CommonCityCodeMapper codeMapper;

    @GET
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public CommonCityCode get() {
        List<CommonCityCode> rs = codeMapper.selectAll();
        return rs.get(0);
    }

    @GET
    @Path("query")
    @TokenNeeded
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public List<CommonCityCode> getByNameAndCode(@HeaderParam ("userId") String userId,@QueryParam("name") String name, @QueryParam("code") String code){
        //可以取到过滤器中解析出来并传入的userId
        // System.out.println(userId);
        List<CommonCityCode> rs = codeMapper.query(name, code);
        return rs;
    }
}
